//
//  MWLocalizableManager.m
//  XiRan-iOS
//
//  Created by Richfit on 2019/11/5.
//  Copyright © 2019 Wood. All rights reserved.
//

#import "MWLocalizableManager.h"

static NSString *const MWUserLanguageKey = @"MWUserLanguageKey";
#define STANDARD_USER_DEFAULT  [NSUserDefaults standardUserDefaults]

@implementation MWLocalizableManager

+ (void)setUserLanguage:(NSString *)userLanguage {
    //跟随手机系统
    if (!userLanguage.length) {
        [self resetSystemLanguage];
        return;
    }
    //用户自定义
    [STANDARD_USER_DEFAULT setValue:userLanguage forKey:MWUserLanguageKey];
    [STANDARD_USER_DEFAULT setValue:@[userLanguage] forKey:@"AppleLanguages"];
    [STANDARD_USER_DEFAULT synchronize];
}

+ (NSString *)userLanguage {
    return [STANDARD_USER_DEFAULT valueForKey:MWUserLanguageKey];
}

/**
 重置系统语言
 */
+ (void)resetSystemLanguage {
    [STANDARD_USER_DEFAULT removeObjectForKey:MWUserLanguageKey];
    [STANDARD_USER_DEFAULT setValue:nil forKey:@"AppleLanguages"];
    [STANDARD_USER_DEFAULT synchronize];
}

+ (void)configCopywriter {
    [YBIBCopywriter sharedCopywriter].videoIsInvalid = [[MWConfigManager manager] objectForKey:@"video_is_invalid" defaultValue:@"视频无效"];
    [YBIBCopywriter sharedCopywriter].videoError = [[MWConfigManager manager] objectForKey:@"video_error" defaultValue:@"视频错误"];
    [YBIBCopywriter sharedCopywriter].unableToSave = [[MWConfigManager manager] objectForKey:@"unable_to_save" defaultValue:@"无法保存"];
    [YBIBCopywriter sharedCopywriter].imageIsInvalid = [[MWConfigManager manager] objectForKey:@"image_is_invalid" defaultValue:@"图片无效"];
    [YBIBCopywriter sharedCopywriter].downloadFailed = [[MWConfigManager manager] objectForKey:@"download_failed" defaultValue:@"图片下载失败"];
    [YBIBCopywriter sharedCopywriter].getPhotoAlbumAuthorizationFailed = [[MWConfigManager manager] objectForKey:@"failed_to_get_album_authorization" defaultValue:@"获取相册权限失败"];
    [YBIBCopywriter sharedCopywriter].saveToPhotoAlbumSuccess = [[MWConfigManager manager] objectForKey:@"save_successful" defaultValue:@"已保存到系统相册"];
    [YBIBCopywriter sharedCopywriter].saveToPhotoAlbumFailed = [[MWConfigManager manager] objectForKey:@"save_failed" defaultValue:@"保存失败"];
    [YBIBCopywriter sharedCopywriter].saveToPhotoAlbum = [[MWConfigManager manager] objectForKey:@"save_album" defaultValue:@"保存到相册"];
    [YBIBCopywriter sharedCopywriter].cancel = [[MWConfigManager manager] objectForKey:@"cancel" defaultValue:@"取消"];
}

@end
